package com.pan.listen.hook;

import com.github.kwhat.jnativehook.keyboard.NativeKeyEvent;
import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
import com.pan.listen.EventListener;

public class NativeListener implements NativeKeyListener {

    private EventListener eventListener;

    public NativeListener(EventListener eventListener) {
        this.eventListener = eventListener;

    }
    @Override
    public void nativeKeyReleased(NativeKeyEvent nativeEvent) {

        NativeKeyListener.super.nativeKeyReleased(nativeEvent);
        int keyCode = nativeEvent.getKeyCode();
        String keyText = NativeKeyEvent.getKeyText(keyCode);
        eventListener.keyPressed(keyText);
    }

    @Override
    public void nativeKeyPressed(NativeKeyEvent nativeEvent) {
        NativeKeyListener.super.nativeKeyPressed(nativeEvent);
        int keyCode = nativeEvent.getKeyCode();
        String keyText = NativeKeyEvent.getKeyText(keyCode);
        eventListener.keyReleased(keyText);
    }
}
